package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.mz.ozy.R;
import com.mz.ozy.WpkApp;
import com.mz.ozy.bean.GoodsImgBean;

import java.util.List;

import cn.jzvd.JzvdStd;


/**
 *
 */

public class ShopDetailBannerAdapter extends StaticPagerAdapter {

    private final Context context;
    List<GoodsImgBean> mBannerListBeans;
    private boolean isPause = false;

    public ShopDetailBannerAdapter(Context context, List<GoodsImgBean> mBannerListBeans) {
        this.mBannerListBeans = mBannerListBeans;
        this.context = context;
    }

    @Override
    public View getView(final ViewGroup container, final int position) {
        View rlShopBanner = LayoutInflater.from(context).inflate(R.layout.item_shop_detail_banner, null);
        ImageView ivShopBanner = rlShopBanner.findViewById(R.id.iv_shop_banner);
        JzvdStd vvShopBanner = rlShopBanner.findViewById(R.id.vv_shop_banner);
        if (mBannerListBeans.get(position).getType() == 0) {
            ivShopBanner.setVisibility(View.VISIBLE);
            vvShopBanner.setVisibility(View.GONE);
            Glide.with(container.getContext()).load(mBannerListBeans.get(position).getImgPath())
                    .transition(DrawableTransitionOptions.withCrossFade())//适用于Drawable
                    .into(ivShopBanner);
        } else {
            ivShopBanner.setVisibility(View.GONE);
            vvShopBanner.setVisibility(View.VISIBLE);
            String proxyUrl = WpkApp.getProxy(context).getProxyUrl(mBannerListBeans.get(position).getImgPath());
            vvShopBanner.setUp(proxyUrl, "");
            if (isPause) {
                vvShopBanner.goOnPlayOnPause();
            } else {
                vvShopBanner.startButton.performClick();
            }
        }

        return rlShopBanner;
    }

    public void setPause(boolean pause) {
        isPause = pause;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mBannerListBeans.size();
    }

}
